package com.naszetatry.controller;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.naszetatry.beans.Edge;
import com.naszetatry.beans.Path;
import com.naszetatry.beans.SearchResult;
import com.naszetatry.beans.Vertex;
import com.naszetatry.login.LValidation;
/**
 * Kontroler mapy
 * @author Maciej Koch
 *
 */
public class MapController {

	private static final String pathsString = "paths";
	private static final String vertexString = "vertex";
	private static final String resultsString = "results"; 

	/**
	 * Zwraca liste sciezek
	 * @param request
	 * @return
	 * lista sciezek
	 */
	public static ArrayList<Path> getPaths(HttpServletRequest request) {
		return (ArrayList<Path>) request.getAttribute(pathsString);
	}
	/**
	 * Ustawia liste sciezek
	 * @param request
	 * @param paths
	 * lista sciezek
	 */
	public static void setPaths(HttpServletRequest request, List<Path> paths) {
		request.setAttribute(pathsString, paths);
	}
	/**
	 * Pobiera liste wierzcholkow
	 * @param request
	 * @return liste wierzcholkow
	 */
	public static ArrayList<Vertex> getVertexes(HttpServletRequest request) {
		return (ArrayList<Vertex>) request.getAttribute(vertexString);
	}
	/**
	 * Ustawia liste wierzcholkow
	 * @param request
	 * @param vertexes
	 * lista wierzcholkow
	 */
	public static void setVertexes(HttpServletRequest request, List<Vertex> vertexes) {
		request.setAttribute(vertexString, vertexes);
	}
	/**
	 * Ustawia wyniki wuszukiwarki
	 * @param request
	 * @param results
	 * wyniki z wyszukiwarki
	 */
	public static void setResults(HttpServletRequest request, List<SearchResult> results) {
		request.setAttribute(resultsString, results);
	}
	/**
	 * Sprawdza czy sa jakies wyniki z wyszukiwarki.
	 * @param request
	 * @return 
	 * true, jesli sa jakies wyniki, false, jesli nie
	 */
	public static boolean isResult(HttpServletRequest request) {
		if(request.getAttribute(resultsString) == null)
			return false;
		return true;
	}
	/**
	 * Pobiera wyniki z wyszukiwarki
	 * @param request
	 * @return
	 * liste wynikow
	 */
	public static ArrayList<SearchResult> getResults(HttpServletRequest request) {
		return (ArrayList<SearchResult>)request.getAttribute(resultsString);
	}
}
